/**
*	插件：reim首页
*	开发者：雨中磐石
*	地址：www.rockoa.com
*	日期：2023-07-17
*/

js.reim = {}

var reim = {
	loadci:0,
	ismobile:0,
	cnum:'',
	uinfo:{},
	ainfo:{},
	companyinfo:{},
	historysarr:{},
	agentarr:{},
	grouparr:{},
	init:function(){
		windowfocus = true;
		viewwidth   = winWb();
		date 		= js.now();
		var str 	= js.getoption('companyinfo'+this.cnum+'');
		if(str)this.shocompanyinfo(js.decode(str));
		this.loaddata('加载中...',false);
		
		if(this.ismobile==1){
			window.onhashchange=function(e){
				reim.onhashchange(e);
			}
		}
		if(this.ismobile==0){
			js.plugin.scrollbar(function(){
				$('#centlist').perfectScrollbar('destroy');
				$('#centlist').perfectScrollbar();
			});
			$(window).focus(function(){windowfocus=true;reim.windowfocus()});
			$(window).blur(function(){windowfocus=false;});
			js.onkeydown=function(kv){
				if(kv==27){
					return reim.closetabsnow();
				}
				return false;
			}
		}
		window.onbeforeunload=function(){
			if(js.nwjs)js.nwjs.unload();
			if(js.unload)js.unload();
		}
		setTimeout('reim.isapprun()',1000);
	},
	isapprun:function(){
		if(!rockbool)return;
		rock.mainFun('addEventListener',{'name':'home'}, function(ret){
			if(ret.stype=='onstop'){windowfocus=false;}
			if(ret.stype=='onresume'){windowfocus=true;reim.windowfocus();}
		});
	},
	windowfocus:function(){
		if(js.notify)js.notify.close();
		if(js.nwjs)js.nwjs.iconok();
	},
	loaddata:function(s,bo){
		js.ajax.get({
			url:'api/company/data?hmode=1&ismobile='+this.ismobile+'',
			cnum:this.cnum,
			loading:s
		}, function(ret){
			reim.showdata(ret.data, bo);
		});
	},
	shuaxins:function(o1){
		o1.innerHTML = js.show.ling(12);
		this.loaddata('', o1);
	},
	showdata:function(da, o1){
		this.loadci++;
		this.alldata = da;
		this.nowdt 	 = da.nowdt;
		this.uinfo	 = da.userinfo;
		this.ainfo	 = da.useainfo;
		js.setoption('companyinfo'+this.cnum+'', da.companyinfo);
		js.setoption('userinfo',this.uinfo);
		js.setoption('useainfo'+this.cnum+'', this.ainfo);
		this.shocompanyinfo(da.companyinfo);
		if(this.ismobile==1){
			$('#namediv').html(this.ainfo.name);
			$('#namesdiv').html(this.ainfo.deptname);
			$('#zhiweidiv').html(this.ainfo.ranking);
			$('#mobilediv').html(js.check.mobilexing(this.ainfo.mobile));
			var type='<font color="#888888">普通用户</font>';
			if(this.ainfo.type=='1')type = '<font color="green">管理员</font>';
			if(this.ainfo.type=='2')type = '<font color="red">创建者</font>';
			$('#unitjibie').html(type);
		}
		if(o1){
			o1.innerHTML = '<i class="icon-refresh"></i> 刷新';
			$('#showdept').html('');
			this.showdept();
		}
		var pzs = da.reim;
		if(this.loadci == 1 && pzs && pzs.url){
			this.cehui = pzs.cehui;
			pzs.id   = da.userinfo.id;
			pzs.name = da.useainfo.name;
			pzs.type = (this.ismobile==0)? 'r':'m';
			pzs.onmessage = function(d){
				reim.onmessage(d);
			}
			importjs('websocket','create',pzs);
		}
		if(this.loadci == 1){
			js.setoption('rockfile', da.rockfile);
			importjs('rockfile','importbase', function(){
				reim.initfile();
			});
			if(nwjs)importjs('nwjs','create',{
				name:this.ainfo.name,
				companyname:this.companyinfo.name,
				systitle:systemtitle
			});
		}
		if(get('tabs_tagent'))reim.tagent.showagent();
		this.showhistory(da.historyarr);
		this.showagents(da.agentarr);
		this.showgroup(da.grouparr);
	},
	
	shocompanyinfo:function(info){
		var logo = 'images/nologo.png';
		if(info.logo)logo = info.logo;
		get('iconindex').href = logo;
		js.setoption('ico_'+this.cnum+'', logo);
		this.companyinfo = info;
		var str = js.getoption('myinfo');
		if(str){
			var arr = js.decode(str);
			adminname = arr.name;
			adminface = arr.face;
		}
		if(get('reim_myface')){
			//if(adminname)get('reim_myface').title = info.name+'-'+adminname;
			if(adminface)get('reim_myface').src=adminface;
		}
		$('#companynamediv').html(info.name)
	},
	changetabs:function(o1,ind){
		$('div[id^="changetabs"]').removeClass('leftactive');
		$('div[id^="centshow"]').hide();
		$('#changetabs'+ind+'').addClass('leftactive');
		$('#centshow'+ind+'').show();
		
		if(ind==1)this.showdept();
		if(ind==2){
			$('#maincenter').hide();
			this.showagent(false);
		}else{
			this.hideagent();
			$('#maincenter').show();
		}
	},
	indnow:0,
	changtab:function(o1,ind){
		if(ind==this.indnow){
			if(ind==0)this.loaddata('加载中...',false);
		}else{
			$('#centshow'+this.indnow+'').hide();
			$('#tabitem'+this.indnow+'').removeClass('tabactive');
			$('#centshow'+ind+'').show();
			$('#tabitem'+ind+'').addClass('tabactive');
		}
		this.indnow = ind;
		if(ind==2)this.showdept();
		if(ind==1)this.showagentwe();
	},
	openmyinfo:function(){
		this.addtabs('tgeren', 'admin/geren', {
			cnum:this.cnum,
			laiyuan:'im'
		});
	},
	showdept:function(){
		if($('#showdept').html() || !this.alldata)return;
		importjs('tree','create',{
			data:this.alldata.deptarr,
			openchliren:true,
			view:'showdept',
			active:false,
			cls:'chatlist',
			onitemclick:function(d){
				reim.showdeptinfo(d);
			}
		});
	},
	showgroup:function(da){
		var i,d,s='',oi=0;
		$('#showgroup').html(s);
		if(da)for(i=0;i<da.length;i++){
			d = da[i];oi++;
			this.showgroups(d);
		}
		$('#groupzs').html(oi+'');
	},
	showgroups:function(d){
		var s='',hei=24,bt='';
		this.grouparr[d.id] = d;
		if(d.bqname)bt+='<span style="margin-left:2px;font-size:10px;background:'+d.bqcolor+'" class="rock-badge">'+d.bqname+'</span>';
		s+='<div onclick="reim.opengroup(\''+d.id+'\')" class="chatlist"><table width="100%"><tr>';
		s+='<td ><div style="height:'+hei+'px;overflow:hidden;padding-right:5px"><img src="'+getface(d.face)+'" style="height:'+hei+'px;width:'+hei+'px"></div></td>';
		s+='<td width="100%">';
		s+='	<div class="name">'+d.name+bt+'</div>';
		s+='</td>';
		s+='</tr></table></div>';
		$('#showgroup').append(s);
	},
	hideagent:function(){
	},
	showagents:function(da){
		var i,d,sto=0;
		for(i=0;i<da.length;i++){
			d = da[i];
			this.agentarr[d.id] = d;
			sto+=parseFloat(d.stotal);
		}
		var o1 = $('#agent_stotal');
		o1.html(''+sto+'');
		if(sto==0){o1.hide();}else{o1.show();}
	},
	stotalagent:function(){
		var sto=0,d,i;
		for(i in this.agentarr){
			d = this.agentarr[i];
			sto+=parseFloat(d.stotal);
		}
		var o1 = $('#agent_stotal');
		o1.html(''+sto+'');
		if(sto==0){o1.hide();}else{o1.show();}
	},
	openagent:function(id){
		var d 	= this.agentarr[id];
		if(!d){js.show.msg('应用不存在');return;}
		$('#agenh_stotal_'+id+'').html('');
		d.stotal = '0';
		this.stotalagent();
		var bh 	= d.mknum,url=d.url;
		var wid = screen.width-100;
		if(wid<950)wid = 950;if(wid>1300)wid = 1300;
		if(bh){
			var we = '';
			if(this.ismobile>0)we='we';
			var cans = {num:bh+this.cnum+d.url,name:d.name,url:'flow/list'+we+'',params:{num:bh,cnum:this.cnum,otype:'company',funitid:d.id,pnum:d.url,ismobile:this.ismobile}};
			if(rockbool){
				rock.mainFun('openWin',{url:NOWURL+xcy.opennei(cans,true)});
			}else{
				js.open(xcy.openurl(cans),wid ,700);
			}
		}else{
			if(url){
				window.open(url);
			}else{
				js.show.msg('未设置打开地址');
			}
		}
	},
	showagentwe:function(){
		if(!this.alldata)return;
		var da = this.alldata.agentarr,agedt={},d,ty,len,d1,s='',i,sto;
		for(i=0;i<da.length;i++){
			d  = da[i];
			ty = d.type;
			if(!agedt[ty])agedt[ty]=[];
			agedt[ty].push(d);
		}
		for(ty in agedt){
			d1 	= agedt[ty];
			len	= d1.length;
			s+='<div style="color:#aaaaaa;padding-left:20px;padding:5px;font-size:14px">&nbsp;&nbsp;'+ty+'('+len+')</div>';
			s+='<div class="agenhclsdiv">';
			for(i=0;i<len;i++){
				d = d1[i];
				sto = d.stotal;
				if(!sto || sto=='0')sto='';
				s+='<div onclick="reim.openagent(\''+d.id+'\')" class="agenhcls"><div><img src="'+getface(d.icons)+'"></div><div>'+d.name+'</div>';
				s+='<span id="agenh_stotal_'+d.id+'" class="badge">'+sto+'</span>';
				s+='</div>';
			}
			s+='</div>';
		}
		$('#centshow1').html('<div style="margin:5px 0px">'+s+'</div>');
	},
	showagent:function(){
		this.addtabs('tagent', 'reim/agent', {
			cnum:this.cnum,
			scroll:true
		});
	},
	showdeptinfo:function(d){
		var we = '';
		if(this.ismobile!=0)we='we';
		this.addtabs('tdept', 'reim/deptinfo'+we+'', d);
	},
	addtabs:function(bh,url, par){
		var sid = 'tabs_'+bh+'',attr='',sty='';
		if(!par)par={};
		if(get(sid)){
			this.showtabs(bh);
			if(reim[bh] && reim[bh].onshow)reim[bh].onshow(par);
			return true;
		}
		$('div[tabs]').hide();
		if(par.scroll){
			sty = 'height:300px;overflow:hidden;position:relative;';
			attr= 'resizes="0"';
		}
		var s = '<div tabs="'+bh+'" '+attr+' id="'+sid+'" style="'+sty+'"><div style="line-height:100px" align="center">'+js.show.ling(50)+'</div></div>';
		var ob = $('#viewzhulist');
		ob.append(s);
		if(this.ismobile==1){
			ob.show();
			this.hashadd = true;
			setTimeout('reim.hashadd=false',50);
			js.location('#'+bh+'');
		}
		xcy.addcont(url, sid, par, function(){
			if(par.scroll && reim.ismobile==0)$('#'+sid+'').perfectScrollbar();
		});
	},
	showtabs:function(bh){
		$('div[tabs]').hide();
		$('#tabs_'+bh+'').show();
	},
	onhashchange:function(e){
		if(this.hashadd)return;
		var old = e.oldURL,ola = old.split('#');
		if(ola[1]){
			var bh = ola[1];
			this.closetabs(bh, true);
		}
	},
	closetabs:function(bh,lbo){
		$('#tabs_'+bh+'').remove();
		reim[bh] = false;
		$('div[tabs]:last').show();
		if(this.ismobile==1){
			if(!lbo && location.hash)js.back();
			var o1 = $('#viewzhulist')
			if(o1.html()=='')o1.hide();
		}
	},
	closetabsnow:function(){
		var obj = $('div[tabs]:visible');
		var bh = obj.attr('tabs');
		if(bh!='home')this.closetabs(bh);
		return false;
	},
	onmessage:function(d){
		var type = d.type;
		if(type=='chat'){
			this.messagechat(d);
		}
		if(type=='todo'){
			this.gethistory();
		}
		if(type=='cehui'){
			this.rechehui(d.messid);
			$('#qipaocont_mess_'+d.messid+'').html('<s class="hui">已撤回</s>');
		}
	},
	messagechat:function(d){
		var bh = 'chat'+d.xxtype+'_'+d.xxid+'';
		if(d.sendid==this.uinfo.id)return;
		this.gethistory();
		if(reim[bh]){
			reim[bh].onmessage(d);
		}
		var istx = false,isatmy=0,ats='';
		if(d.atid>0)isatmy=1;
		if(d.atid>0 && d.atid==this.ainfo.id)isatmy=2;//@我的
		if(d.mess && d.title && !windowfocus)istx = true;
		if(istx && isatmy==1)istx = false;
		if(istx){
			if(isatmy==2)ats='@我';
			if(js.getoption('tantodo')!='no' || isatmy==2){
				if(rockbool){
					rock.mainFun('Notification', {
						msg:jm.base64decode(d.mess),
						title:jm.base64decode(d.title)+ats
					});
					return;
				}
				js.notify.send({
					body:jm.base64decode(d.mess),
					title:jm.base64decode(d.title)+ats,
					icon:d.icon,
					data:d,
					click:function(){
						reim.notifyclick(this.data);
						return true;
					}
				});
			}
			if(js.nwjs)js.nwjs.jumpicon();
			if(js.getoption('shengtodo')!='no')js.notify.paly();//发声音
		}
	},
	notifyclick:function(d){
		var sid = 'hist'+d.xxtype+''+d.xxid+'';
		if(d.xxtype=='0' || d.xxtype=='1'){
			this.openchat(sid);
		}
	},
	gethistory:function(){
		if(this.histbool)return;
		this.histbool = true;
		js.ajax.get({
			url:'api/reim/history',
			cnum:this.cnum,
			urlda:{
				lastdt:this.nowdt
			},
			onerror:function(){
				reim.histbool = false;
			}
		}, function(ret){
			reim.showhistory(ret.data.historyarr, true);
			reim.nowdt = ret.data.nowdt;
		});
	},
	rechehui:function(id){
		var d,sid,robo=false;
		for(sid in this.historysarr){
			d = this.historysarr[sid];
			if(d.lastid==id){
				d.lastid = '0';
				robo = true;
				break;
			}
		}
		if(robo)this.gethistory();
	},
	sortpaxh:function(d1,d2){
		if(d1.optdt > d2.optdt){
			return -1;
		}else if(d1.optdt < d2.optdt){
			return 1;
		}else{
			return 0;
		}
	},
	showhistory:function(da, sys){
		this.histbool = false;
		if(!da)return;
		da.sort(this.sortpaxh);//排序
		for(var i=0;i<da.length;i++){
			this.showhistorys(da[i],sys);
		}
		if(get('historylist').innerHTML==''){
			$('#historylist_tems').show();
		}else{
			$('#historylist_tems').hide();
		}
		this.stotalchat();
	},
	showhistorys:function(d,sys){
		var s= '',hei= 34,max='auto',sid='hist'+d.type+''+d.sendid+'',col='',not='',bt = d.sendname;
		if(this.ismobile!=0){
			hei = 46;
			max = ''+(viewwidth-hei-80)+'px';
		}
		$('#'+sid+'').remove();
		this.historysarr[sid] = d;
		if(d.stotal==0)not='none';
		if(d.title)bt = jm.base64decode(d.title);
		if(d.type=='9')col=maincolor;
		if(d.bqname)bt+='<span style="margin-left:2px;font-size:10px;background:'+d.bqcolor+'" class="rock-badge">'+d.bqname+'</span>';
		s+='<div oncontextmenu="reim.rightmenu(this,event);return false;" id="'+sid+'" onclick="reim.openchat(\''+sid+'\')" class="chatlist">';
		s+='<table width="100%"><tr>';
		s+='<td ><div style="height:'+hei+'px;overflow:hidden;padding-right:8px"><img src="'+getface(d.sendface)+'" style="height:'+hei+'px;width:'+hei+'px"></div></td>';
		s+='<td width="100%">';
		s+='	<div class="name" style="color:'+col+';max-width:'+max+'">'+bt+'</div>';
		s+='	<div class="cont" style="max-width:'+max+'">'+jm.base64decode(d.lastcont)+'</div>';
		s+='</td>';
		s+='<td nowrap align="right">';
		s+='	<div>&nbsp;<span id="'+sid+'_stotal" style="border-radius:10px;background:red;padding:2px 6px;font-size:12px;color:white;display:'+not+'">'+d.stotal+'</span></div>';
		s+='	<div class="cont" style="width:45px">'+this.showdt(d.optdt)+'</div>';
		s+='</td>';
		s+='</tr></table>';
		
		/*
		s+='<div style="height:'+hei+'px;overflow:hidden;padding-right:8px"><img src="'+getface(d.sendface)+'" style="height:'+hei+'px;width:'+hei+'px"></div>';
		s+='<div style="flex:1">';
		s+='	<div class="name" style="color:'+col+'">'+bt+'</div>';
		s+='	<div class="cont">'+jm.base64decode(d.lastcont)+'</div>';
		s+='</div>';
		s+='	<div style="background:red">';
		s+='		<div>&nbsp;<span id="'+sid+'_stotal" style="border-radius:10px;background:red;padding:2px 6px;font-size:12px;color:white;display:'+not+'">'+d.stotal+'</span></div>';
		s+='		<div class="cont" style="width:40px">'+this.showdt(d.optdt)+'</div>';
		s+='	</div>';
		*/
		s+='</div>';
		if(sys){
			$('#historylist').prepend(s);
		}else{
			$('#historylist').append(s);
		}
	},
	stotalchat:function(){
		var obj = $('#historylist').find('span[id$=_stotal]'),so=0;
		for(var i=0;i<obj.length;i++){
			so+=parseFloat(obj[i].innerHTML);
		}
		var o1 = $('#chat_stotal');
		o1.html(''+so);
		if(so==0){o1.hide();}else{o1.show();}
	},
	rightmenu:function(o1,evt){
		var bh = o1.id;
		var d  = this.historysarr[bh];
		var da = [{name:'打开',lx:0}];
		//if(this.ismobile==0 && (d.type=='0' || d.type=='1'))da.push({name:'打开(新窗口)',lx:2});
		if(d.type!='9')da.push({name:'删除此记录',lx:1});
		importjs('menu','create', {
			obj:$(o1),data:da,width:150,
			onclick:function(d1){
				reim.rightmenuclick(d1.lx, d, o1);
			},
			showXY:{
				left:evt.clientX+3,
				top:evt.clientY+3
			}
		});
	},
	rightmenuclick:function(lx,d,o1){
		if(lx==0)this.openchat(o1.id);
		if(lx==2)this.openchat(o1.id, true);
		if(lx==1){
			$(o1).remove();
			js.ajax.get({
				url:'api/reim/historydel',
				cnum:this.cnum,
				urlda:{
					type:d.type,
					id:d.sendid
				}
			});
			this.stotalchat();
		}
	},
	historyfirst:function(d){
		this.showhistorys(d, true);
	},
	showdt:function(sj){
		var ops = sj.substr(11,5);
		if(sj.indexOf(date)!=0){
			ops=sj.substr(5,5);
		}
		return ops;
	},
	openchat:function(bh, onew){
		var d = this.historysarr[bh];
		if(!d)return;
		this.hidestotal(d.type,d.sendid);
		var type = d.type;
		if(type=='0'){
			this.openchats(d,onew);
		}else if(type=='1'){;
			this.opengroup(d.sendid, d,onew);
		}else if(type=='4'){
			this.openagent(d.sendid);
		}else if(type=='9'){
			js.modal.confirm('是否切换到单位“'+d.sendname+'”吗？', function(jg){
				if(jg=='yes')reim.changecom(d);
			});
		}else{
			js.show.error('未开发打开');
		}
	},
	changecom:function(d){
		if(this.ismobile==0){
			xcy.opencompany({hmode:1,name:d.sendname,num:d.num});
		}else{
			var cans = {url:'we/index',name:d.sendname,params:{cnum:d.num,title:d.sendname}};
			var url = xcy.openurl(cans);
			js.location(url);
		}
	},
	opengroup:function(id, ds,onew){
		var d = this.grouparr[id];
		if(!d && ds && ds.type=='1'){
			ds.ranking = ds.ushu;
			this.openchats(ds,onew);
			return;
		}
		if(!d){js.show.error('会话群不存在了');return;}
		this.openchats({
			type:'1',
			sendid:d.id,
			sendname:d.name,
			sendface:d.face,
			ranking:d.ushu,
			bqname:d.bqname,
			bqcolor:d.bqcolor
		},onew);
	},
	hidestotal:function(ty,sid){
		$('#hist'+ty+''+sid+'_stotal').html('0').hide();
		this.stotalchat();
	},
	openchats:function(d,onew){
		var ds= {type:d.type,id:d.sendid,name:d.sendname,face:d.sendface,bh:'chat'+d.type+'_'+d.sendid+'',ranking:d.ranking};
		if(d.deptname)ds.deptname = d.deptname;
		if(d.ranking)ds.ranking = d.ranking;
		if(d.bqname){
			ds.bqname = d.bqname;
			ds.bqcolor = d.bqcolor;
		}
		if(d.type=='0' || d.type=='1')ds.cnum = this.cnum;
		this.hidestotal(d.type,d.sendid);
		var we= '';
		if(this.ismobile==1)we='we';
		if(rockbool){
			//ds.isnew = true;
			//var surl = xcy.opennei({url:'reim/chatwe',name:ds.name,params:ds},true);
			//rock.mainFun('openWin', {url:NOWURL+surl,name:ds.name});
			//return;
		}
		ds.isapp = rockbool;
		if(onew){
			this.closetabs(ds.bh);
			ds.isnew = true;
			var surl = xcy.openurl({url:'reim/chat'+we+'',name:ds.name,params:ds});
			js.open(surl, 600,500)
		}else{
			this.addtabs(ds.bh, 'reim/chat'+we+'', ds);
		}
	},
	addplus:function(o1){
		this.showmenu(get('cogbtn'));
	},
	showmenu:function(o1){
		var d = [];
		d.push({'name':'刷新',lx:'sx'});
		if(this.uinfo.type=='2')d.push({'name':'平台管理',lx:'plat'});
		d.push({'name':'单位主页',lx:'manage'});
		d.push({'name':'切换单位',lx:'qhdw'});
		d.push({'name':'创建群',lx:'create'});
		d.push({'name':'设置',lx:'cog'});
		d.push({'name':'退出',lx:'exit'});
		var off = $(o1).offset();
		importjs('menu','create', {
			obj:$(o1),data:d,width:120,
			onclick:function(d1){
				reim.clickcogclick(d1);
			},
			showXY:{
				left:60,
				top:off.top+d.length*36
			}
		});
	},
	creagegroup:function(){
		js.modal.prompt({
			title:'创建会话群',
			msg:'请输入会话群名',
			type:'text'
		}, function(jg,txt){
			if(jg=='yes' && txt)reim.creategroup(txt);
		});
	},
	clickcogclick:function(d){
		var lx = d.lx;
		if(lx=='sx'){
			js.loading('刷新中...');
			js.reload();
		}
		if(lx=='create'){
			this.creagegroup();
		}
		if(lx=='exit'){
			this.exit();
		}
		if(lx=='plat'){
			xcy.openkey({url:'home'});
		}
		if(lx=='manage')xcy.opencompany({
			name:this.companyinfo.name,
			num:this.cnum,
			hmode:'0'
		}, true);
		if(lx=='cog')this.addtabs('tcog', 'reim/cog');
		if(lx=='qhdw')this.qhdw();
	},
	qhdw:function(){
		this.addtabs('tcompany', 'reim/company',{cnum:this.cnum,ismobile:this.ismobile});
	},
	wecog:function(){
		this.addtabs('tcogwe', 'we/cog');
	},
	exit:function(){
		js.modal.confirm('确定要退出系统嘛？', function(jg){
			if(jg=='yes')reim.loginexitok();
		});
	},
	loginexitoks:function(){
		js.show.success('已退出');
		js.setoption('token');
		js.setoption('myinfo');
		js.setoption('defnowurl');
		js.reload();
	},
	loginexitok:function(){
		js.ajax.get({
			url:'api/geren/exit',
			loading:'退出中...',
			onsuccess:function(){
				reim.loginexitoks();
			},
			onerror:function(){
				reim.loginexitoks();
			}
		});
	},
	creategroup:function(na){
		js.ajax.post({
			url:'api/reim/creategroup',
			cnum:this.cnum,
			loading:'创建中..',
			loadsuccess:'创建成功',
			data:{
				name:na
			}
		},function(ret){
			reim.loaddata('');
		});
	},
	initfile:function(){
		js.rockfile.importjs();
		if(!$.rockfileupload)return;
		this.fileobj = $.rockfileupload({
			inputfile:'allfileinput',
			initpdbool:false,
			urlparams:{noasyn:'yes',thumb:'url',shuiyin:'size'},
			onchange:function(d){
				reim.sendfileshow(d);
			},
			onprogress:function(f,per,evt){
				reim.upprogresss(f,per);
			},
			onsuccess:function(f,str,o1){
				reim.sendfileok(f,str);
			},
			onerror:function(str){
				js.show.error(str);
			}
		});
	},
	sendfileshow:function(d){
		if(d.bh && reim[d.bh])reim[d.bh].sendfileshow(d);
	},
	upprogresss:function(d,per){
		if(d.bh && reim[d.bh])reim[d.bh].upprogresss(d,per);
	},
	sendfileok:function(d,str){
		if(d.bh && reim[d.bh])reim[d.bh].sendfileok(d,str);
	},
	backemts:function(str){
		var bh = this.nowbh;
		reim[bh].backemts(str);
	},
	readclip:function(o1,evt){
		var clipboardData = evt.clipboardData;
		if(!clipboardData)return;
		var bh = $(o1).attr('bh');
		if(bh)for(var i=0; i<clipboardData.items.length; i++){  
			var item = clipboardData.items[i];  
			if(item.kind=='file'&&item.type.match(/^image\//i)){  
				var blob = item.getAsFile(),reader = new FileReader();  
				reader.onload=function(){  
					var cont=this.result;
					if(reim[bh])reim[bh].readclipshow(cont);
				}  
				reader.readAsDataURL(blob);
			}  
		} 
	},
	upbase64:function(nuid, bh){
		var o = get('jietuimg_'+nuid+'');
		if(!o)return;
		var strnr = o.src
		this.fileobj.sendbase64(strnr,{bh:bh,nuid:nuid});
	}
}